import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
const _asset1 = 'laser.wav';
const _asset2 = 'nasa_on_a_mission.mp3';

class MusicaPlayer extends StatefulWidget {
  const MusicaPlayer({Key? key}) : super(key: key);

  @override
  State<MusicaPlayer> createState() => _MusicaPlayerState();
}

class _MusicaPlayerState extends State<MusicaPlayer> {
  AudioPlayer? player;

  @override
  void initState() {
    // TODO: implement initState
    player = AudioPlayer();
    print("----------initState");
    super.initState();
  }

  setSource() async {
    print("----------setSource");
    // await player?.setSource(AssetSource(_asset1));
  }

  play() async {
    print("----------play");
    // await player?.stop();
    await player?.play(AssetSource("firecracker_music1.mp3"));
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
     body: Column(
       crossAxisAlignment: CrossAxisAlignment.center,
       mainAxisAlignment: MainAxisAlignment.center,
       children: [
         GestureDetector(
             onTap: (){
               setSource();
             },
             child: Container(
                 width: 100,
                 height: 100,
                 color: Colors.red,
                 child: Text("set"))),

         GestureDetector(
             onTap: (){
               play();
             },
             child: Container(
                 width: 100,
                 height: 100,
                 color: Colors.blue,
                 child: Text("play"))),
       ],
     ),
    );
  }
}
